#include<bits/stdc++.h>
using namespace std;
const int N=5005,mod=998244353;
int n,a[N],sum[N],f[N];
inline void Mod(int &x){return (x>=mod)&&(x-=mod),void();}
int main(){
	freopen("after.in","r",stdin);
	freopen("after.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	f[0]=1;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=n;++j) Mod(sum[j]=f[j]+(j?sum[j-1]:0));
		int lt=0,rt=n+1;
		for(int j=i-1;j;--j)
			if(a[j]>a[i]){lt=j;break;}
		for(int j=i+1;j<=n;++j)
			if(a[j]>a[i]){rt=j;break;}
		for(int j=lt+1;j<rt;++j)
			Mod(f[j]+=(sum[j-1]-(lt?sum[lt-1]:0)+mod)%mod);
	}
	printf("%d\n",f[n]);
	return 0;
}

